#include <utils.h>

#include <string>

int main(int argc, char* argv[]) {
  SDL_Log("Hello, world!");
  CK_SDL_ERR(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO));
  CK_SDL_ERR(TTF_Init());
  CK_SDL_ERR(Mix_Init(MIX_INIT_MP3 | MIX_INIT_OGG));
  SDL_Window* window = SDL_CreateWindow("Hello, world!", 1280, 720, 0);
  SDL_Renderer* renderer = SDL_CreateRenderer(window, nullptr);
  TTF_TextEngine* text_engine = TTF_CreateRendererTextEngine(renderer);
  SDL_SetRenderDrawColor(renderer, 200, 200, 200, 200);
  TTF_Font* font = TTF_OpenFont(
      "/usr/share/fonts/opentype/noto/NotoSansCJK-Regular.ttc", 24);
  TTF_Text* mouse_text =
      TTF_CreateText(text_engine, font, "Mouse: None, x: 0 y: 0", 0);
  TTF_SetTextColor(mouse_text, 10, 10, 10, 255);
  bool is_running = true;
  SDL_Event event;
  glm::vec2 mouse_pos;
  std::string mouse_buffer;
  std::string mouse_state;
  while (is_running) {
    while (SDL_PollEvent(&event)) {
      if (event.type == SDL_EVENT_QUIT) {
        is_running = false;
      }
    }
    auto state = SDL_GetMouseState(&mouse_pos.x, &mouse_pos.y);
    if (state & SDL_BUTTON_LMASK) {
      mouse_state = "Left";
    } else if (state & SDL_BUTTON_MMASK) {
      mouse_state = "Middle";
    } else if (state & SDL_BUTTON_RMASK) {
      mouse_state = "Right";
    } else {
      mouse_state = "None";
    }
    mouse_buffer = "鼠标信息：Mouse: " + mouse_state +
                   ", x: " + std::to_string(static_cast<int>(mouse_pos.x)) +
                   " y: " + std::to_string(static_cast<int>(mouse_pos.y));
    TTF_SetTextString(mouse_text, mouse_buffer.c_str(), 0);
    SDL_RenderClear(renderer);

    TTF_DrawRendererText(mouse_text, mouse_pos.x + 10, mouse_pos.y + 10);

    SDL_RenderPresent(renderer);
  }

  return 0;
}